<?php if (!defined('insite')) die("no access"); 
require "opt.php";
$db = new Connect ($config["ctype"], $config["db_host"], $config["db_name"], $config["db_user"], $config["db_upwd"],$config["odbc_driver"],$config["debug"]); 
if($_GET["del"])
{
 $dell = checknum(substr($_GET["del"],0,2));
 $db->query("DELETE  FROM mwc_vote_list WHERE id='".$dell."'");
}
?><table align="center" width='90%'  class='tableMain'>
		<tr>
			<td colspan="3"  class='zagstyle'><?=vote_mngr_title?></td>
		</tr>
		<tr>
			<td><?=vote_top_name?></td>
			<td><?=vote_top_address?></td>
			<td><?=dl_manager_optinos?></td>
		</tr><?
	$wats_v = $db->query("SELECT * FROM mwc_vote_list");
	while($result = $db->fetcharray($wats_v))
	{
		echo "<tr><td>".$result["top_name"]."</td><td>".$result["top_addres"]."</td><td><a href='".$config["siteaddress"]."/?p=usercp&ss=voteadm&edit=".$result["id"]."'>[edit]</a><a href='".$config["siteaddress"]."/?p=usercp&ss=voteadm&del=".$result["id"]."'>[delete]</a></td></tr>";
	}
	
if (!$_REQUEST["addvote"])
{
?></table><?
if ($_REQUEST["addvt"])
{
	$t_name = validate(substr($_POST["topname"],0,15));
	$t_addr = htmlspecialchars(substr($_POST["topadress"],0,100));
	$t_pict = htmlspecialchars(substr($_POST["picadress"],0,100));
	$t_flag = checknum(substr($_POST["voteflag"],0,1));
	$t_cred = checknum(substr($_POST["votecred"],0,10));
	if (strlen($t_name)>2 && strlen($t_addr)>5)	$db->query("INSERT INTO mwc_vote_list (top_name,top_addres,top_pic,flag,credits) VALUES('".$t_name."','".$t_addr."','".$t_pict."','".$t_flag."','".$t_cred."')");
	header("Location: ".$config["siteaddress"]."/?p=usercp&ss=voteadm");
}elseif($_REQUEST["eddvt"])
{
	$t_num = checknum(substr($_POST["hvalue"],0,2));
	$t_name = validate(substr($_POST["topname"],0,15));
	$t_addr = htmlspecialchars(substr($_POST["topadress"],0,100));
	$t_pict = htmlspecialchars(substr($_POST["picadress"],0,100));
	$t_flag = checknum(substr($_POST["voteflag"],0,1));
	$t_cred = checknum(substr($_POST["votecred"],0,10));
	if (strlen($t_name)>2 && strlen($t_addr)>5)	$db->query("UPDATE mwc_vote_list SET top_name='".$t_name."',top_addres='".$t_addr."',top_pic='".$t_pict."',flag='".$t_flag."',credits='".$t_cred."' WHERE id='".$t_num."'");
	 header("Location: ".$config["siteaddress"]."/?p=usercp&ss=voteadm");
	
}
?> 
<table align="center" valign="top" width='90%' >
<tr>
	<form method="POST" align = "center">
	<td colspan="3" align="center"><input type="submit" name="addvote" value="add" class="t-button"></td>
	</form>
	</tr>

	</table>
<?}

if ($_REQUEST["addvote"] or $_GET["edit"])
{
$b_name = "addvt";
$b_value = "add";
$num = checknum(substr($_GET["edit"],0,2));
if ($num>0 && !$_REQUEST["addvote"])
{
 $res=$db->fetcharray($db->query("SELECT * FROM mwc_vote_list WHERE id='".$num."'"));
 $b_name = "eddvt";
 $b_value = "edit";
} 
?>
	<form method="post" action="">
	<table align="center" width='90%'  class='tableMain'>
		<tr><td><?=vote_top_name?></td><td><input type="text" class="texbx" name="topname" value="<?=$res["top_name"]?>"></td></tr>
		<tr><td><?=vote_top_address?></td><td><input type="text" class="texbx" name="topadress" value="<?=$res["top_addres"]?>"></td></tr>
		<tr><td><?=vote_pictr_adr?></td><td><input type="text" class="texbx" name="picadress" value="<?=$res["top_pic"]?>"></td></tr>
		<tr><td><?=vote_flag?></td><td><input type="text" class="texbx" name="voteflag" value="<?=$res["flag"]?>"></td></tr>
		<tr><td><?=vote_cred?></td><td><input type="text" class="texbx" name="votecred" value="<?=$res["credits"]?>"><input type="hidden" name="hvalue" value="<?=$num?>"></td></tr>
		<tr><td colspan="2" align="center"><input type="submit" name="<?=$b_name?>" value="<?=$b_value?>" class="t-button"></td></td>
		<tr><td colspan="2" align="center"><?=vote_des_adm?></td></tr>
	</table>
	</form>
<?}?><br><br><br>
<table align="center" width='90%' ><form method="post" action="" name="ch_top" >
<tr><td align="center" colspan="2"><select name="chsn_top" onChange='document.ch_top.submit();' class="texbx" style="height:20px">
<option>Choose top</option>
<?
	$top_list = $db->query("SELECT id,top_name FROM mwc_vote_list");
	while($result = $db->fetchrow($top_list))
	echo "<option value='".$result[0]."'>".$result[1]."</option>";
?>
</select></td></tr><? if ($_REQUEST["chsn_top"])
{
	$top_num = checknum(substr($_POST["chsn_top"],0,2));
	$acc_list = $db->query("SELECT memb___id,clicks FROM mwc_vote_top WHERE top_id='".$top_num."'");
	echo "<tr><td align='center' style='font-weight:bold'>Account</td><td align='center' style='font-weight:bold'>Clicks</td></tr>";
	while($result = $db->fetcharray($acc_list))
	echo "<tr><td align='center'>".$result["memb___id"]."</td><td align='center'>".$result["clicks"]."</td></tr>";
}
?></form></table> 